<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>QUnit 'ecdsamod.js NIST EC Test Vector' test</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>


<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>

<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>
<script src="../src/ecparam-1.0.js"></script>

<script src="ecc-testvectors.js"></script>

<script type="text/javascript">
$(document).ready(function(){


var hashAAA256Hex = KJUR.crypto.Util.sha256("aaa"); // SHA256 hash value of string "aaa"
var hashAAB256Hex = KJUR.crypto.Util.sha256("aab"); // SHA256 hash value of string "aab"
var ECK1PUBHEX = "04a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425"; // k1.pub.pem

function checkTestVector(curve, tv) {
    var biPrv = new BigInteger(tv.k, 10);
    equal(tv.k, biPrv.toString(10), "k=" + tv.k);

    var biX = new BigInteger(tv.x, 16);
    var biY = new BigInteger(tv.y, 16);

    var ec = new KJUR.crypto.ECDSA({curve: curve, prv: biPrv.toString(16) });
    ec.generatePublicKeyHex();
    var pub = ec.getPublicKeyXYHex();
    var biPubX = new BigInteger(pub.x, 16);
    var biPubY = new BigInteger(pub.y, 16);
    equal(biX.toString(16), biPubX.toString(16), "X with k=" + tv.k);
    equal(biY.toString(16), biPubY.toString(16), "Y with k=" + tv.k);
}

test("generatePublicKey (secp256r1)", function() {
  for (var i=0; i<ECC_TESTVECTORS.secp256r1.length; i++) {
    checkTestVector("secp256r1", ECC_TESTVECTORS.secp256r1[i]);
  }
});

test("generatePublicKey (secp384r1)", function() {
  for (var i=0; i<ECC_TESTVECTORS.secp384r1.length; i++) {
    checkTestVector("secp384r1", ECC_TESTVECTORS.secp384r1[i]);
  }
});

test("generatePublicKey (secp521r1)", function() {
  for (var i=0; i<ECC_TESTVECTORS.secp521r1.length; i++) {
    checkTestVector("secp521r1", ECC_TESTVECTORS.secp521r1[i]);
  }
});

});
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>

<b>NOTE:</b>
<p>
In 10.4.1 or before, only secp256r1(P-256), secp256k1, and secp384r1(P-384) curves have been supported.<br/>
From 10.5.0(2021-Nov-21), secp192r1, secp224r1 and secp521r1(P-521) are also supported.<br/>
NIST EC test vectors are defined in <a href="ecc-testvectors.js">ecc-testvectors.js</a>.
</p>

<p>
<a href="index.html">INDEX</a> | 
ECC related QUnit test pages: 
<a href="qunit-do-crypto.html">crypto.js</a> | 
<a href="qunit-do-crypto-ecdsa.html">crypto.js Signature class for ECDSA</a> | 
<a href="qunit-do-ecdsamod.html">ecdsa-modified.js</a> | 
<a href="qunit-do-ecdsamod-unsupport.html">ecdsa-modified unsupported curve</a> | 
<a href="qunit-do-ecparam.html">ecparam.js</a> | 
</p>

</body>
</html>

